package com.zjy.business.system.manager.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.github.pagehelper.PageInfo;
import com.zjy.business.system.domain.entity.SysConfig;
import com.zjy.business.system.domain.manager.query.ManagerListPageSysConfigQuery;
import com.zjy.business.system.manager.service.ManagerSysConfigService;
import com.zjy.log.annotation.OperationLog;
import com.zjy.log.enums.LogBusinessType;
import com.zjy.web.domain.model.Result;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 后台管理-系统配置
 */
@RestController
@RequestMapping("/manager/sysConfig")
@RequiredArgsConstructor
@Slf4j
public class ManagerSysConfigController {

    final private ManagerSysConfigService managerSysConfigService;

    final private static String MODULE_NAME = "系统配置管理";

    /**
     * 新增或者修改配置
     */
    @PostMapping("/saveOrUpdate")
    @SaCheckPermission("system:sysConfig:save_update")
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.INSERT_UPDATE)
    public Result<Void> saveOrUpdate(@RequestBody SysConfig form) {
        managerSysConfigService.saveOrUpdate(form);
        return Result.SUCCESS();
    }

    /**
     * 删除
     * @param id id
     */
    @GetMapping("/remove")
    @SaCheckPermission("system:sysConfig:remove")
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.DELETE)
    public Result<Void> remove(@NotNull(message = "id不能为空") Long id) {
        managerSysConfigService.remove(id);
        return Result.SUCCESS();
    }

    /**
     * 分页查询系统配置
     */
    @GetMapping("/listPageSysConfig")
    @SaCheckPermission("system:sysConfig:pageList")
    public Result<PageInfo<SysConfig> > listPageSysConfig(ManagerListPageSysConfigQuery query) {
        return Result.SUCCESS(managerSysConfigService.listPageSysConfig(query));
    }

}
